#define DEBUG
#include <cstdio>

using namespace std;

const int maxq=300000, maxn=600012;

class TreeArray {
public:
  int a[maxn+1], v[maxn+1], n;

  void update() {
    v[0]++;
  }

  inline int lowbit(int x) {
    return (-x)&x;
  }

  void set(int i, int x) {
    for (; i<=n; i+=lowbit(i)) {
      if (v[i]!=v[0]) {
	v[i]=v[0], a[i]=0;
      }
      a[i]+=x;
    }
  }

  int get(int o) {
    int ret=0;
    for (; o>0; o-=lowbit(o)) {
      if (v[o]!=v[0]) {
	v[o]=v[0], a[o]=0;
      }
      ret += a[o];
    }
    return ret;
  }
};

class Ques {
public:
  int type, x, y, z;
};

void calcAns(int l, int r, Ques a[], int ans[], TreeArray &tree) {
  if (l!=r) {
    int mid=(l+r)/2;
    calcAns(l, mid, a, ans, tree);
    calcAns(mid+1, r, a, ans, tree);

    tree.update();
    for (int i=l, j=mid+1; j<=r; j++) {
      for (; i<=mid && a[i].x>=a[j].x; i++) {
	if (a[i].type) {
	  tree.set(a[i].y+1, a[i].type);
	  tree.set(a[i].z+2, -a[i].type);
	}
      }
      if (!a[j].type) {
	ans[a[j].z] += tree.get(a[j].y+1);
      }
    }

    static Ques temp[maxq+1];
    for (int i=l, j=mid+1, now=l; i<=mid || j<=r; ) {
      if (j>r || (i<=mid && a[i].x>=a[j].x)) {
	temp[now++] = a[i++];
      } else {
	temp[now++] = a[j++];
      }
    }
    for (int i=l; i<=r; i++) {
      a[i] = temp[i];
    }
  }
}

void solve(int n, int m, Ques q[], int ans[]) {
  if (m) {
    static Ques temp[maxq+1];
    static TreeArray treea;
    treea.n = 2*n+1;

    for (int i=1; i<=m; i++) {
      if (q[i].type) {
	temp[i].type=1, temp[i].x=q[i].y+q[i].z+q[i].x, temp[i].y=q[i].y, temp[i].z=q[i].y+q[i].z;
      } else {
	temp[i].type=0, temp[i].x=q[i].y+q[i].x, temp[i].y=q[i].y, temp[i].z=q[i].z;
      }
    }
    calcAns(1, m, temp, ans, treea);

    for (int i=1; i<=m; i++) {
      if (q[i].type) {
	temp[i].type=-1, temp[i].x=q[i].x-1, temp[i].y=q[i].y, temp[i].z=q[i].z+q[i].y;
      } else {
	temp[i]=q[i];
      }
    }
    calcAns(1, m, temp, ans, treea);
  }
}

int main() {
  freopen("frontier.in", "r", stdin);
  freopen("frontier.out", "w", stdout);

  static int ans[maxq+1];
  static Ques ques[maxq+1], temp[maxq+1];
  int num, n, q, tempn;
  scanf("%d %d %d", &num, &n, &q);
  for (int i=1; i<=q; i++) {
    int opt;
    scanf("%d", &opt);
    if (opt==1) {
      scanf("%d %d %d %d", &ques[i].type, &ques[i].x, &ques[i].y, &ques[i].z);
    } else {
      scanf("%d %d", &ques[i].x, &ques[i].y);
      ques[i].z = i;
    }
  }

  //1
  tempn=0;
  for (int i=1; i<=q; i++) {
    if (!ques[i].type || ques[i].type==1) {
      temp[++tempn] = ques[i];
    }
  }
  solve(n, tempn, temp, ans);

  //2
  tempn=0;
  for (int i=1; i<=q; i++) {
    if (!ques[i].type || ques[i].type==2) {
      temp[++tempn] = ques[i];
      temp[tempn].y = n-ques[i].y+1;
    }
  }
  solve(n, tempn, temp, ans);

  //3
  tempn=0;
  for (int i=1; i<=q; i++) {
    if (!ques[i].type || ques[i].type==3) {
      temp[++tempn] = ques[i];
      temp[tempn].x = n-ques[i].x+1;
    }
  }
  solve(n, tempn, temp, ans);

  //4
  tempn=0;
  for (int i=1; i<=q; i++) {
    if (!ques[i].type || ques[i].type==4) {
      temp[++tempn] = ques[i];
      temp[tempn].x = n-ques[i].x+1;
      temp[tempn].y = n-ques[i].y+1;
    }
  }
  solve(n, tempn, temp, ans);

  for (int i=1; i<=q; i++) {
    if (!ques[i].type) {
      printf("%d\n", ans[i]);
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
